package ${package_name}.dao.impl;

import com.chenfan.ccp.plug.mybatis.util.MybatisPlus;
import com.chenfan.ccp.plug.mybatis.util.MybatisPlusBuild;
import ${package_name}.dao.${class_name}Dao;
import ${package_name}.${class_package}.${class_name}Po;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
/**
* ${entity_name}的dao层
**/
@Repository
public class ${class_name}DaoImpl implements ${class_name}Dao {
p4jprivate final int PAGE_SIZE = 10;

@Override
p4jpublic int save${class_name}IfNotExist(${class_name}Po ${lower_class_name}Po) {

return ${lower_class_name}Po.save();
}

@Override
p4jpublic int mod${class_name}(${class_name}Po ${lower_class_name}Po) {

return ${lower_class_name}Po.update(${lower_class_name}Po.build().eq(${class_name}Po::getId
, ${lower_class_name}Po.getId()));
}

@Override
p4jpublic int del${class_name}ByIds(Long... ids) {

${class_name}Po ${lower_class_name}Po = ${new_class_instance};

${lower_class_name}Po.setDeletedFlag(Boolean.TRUE);

return ${lower_class_name}Po.update(${lower_class_name}Po.build().in(${class_name}Po::getId, ids));
}


@Override
p4jpublic ${class_name}Po find${class_name}ById(Long id) {

MybatisPlusBuild build = new MybatisPlusBuild(${class_name}Po.class);

build.eq(${class_name}Po::getDeletedFlag, Boolean.FALSE);

build.eq(${class_name}Po::getId, id);


return MybatisPlus.getInstance().findOne( ${new_class_instance}, build);
}


@Override
p4jpublic List
<${class_name}Po> find${class_name}ByAll(${class_name}Po ${lower_class_name}Po, Integer page, Integer size) {
    MybatisPlusBuild build = new MybatisPlusBuild(${class_name}Po.class);

    build.eq(${class_name}Po::getDeletedFlag, Boolean.FALSE);

    if (${lower_class_name}Po.getId() == null) {

    ${param_condition}

    if (page == null) {
    page = 1;
    }


    build.page(page, size==null?PAGE_SIZE:size);

    } else {
    build.eq(${class_name}Po::getId, ${lower_class_name}Po.getId());
    }


    return MybatisPlus.getInstance().findAll( ${new_class_instance}
    , build);
    }


    }
